using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using GonzalesCore.CoreManagers;
using Jamila2.Tools;

public partial class GonzalesAdminTestEmail : System.Web.UI.Page
{
    #region Variables

    protected PrivateLoginSession CurrentPrivateSession = null;
    protected LogManager CurLogManager = null;

    #region ErrorMessage
    protected string ErrorMessage
    {
        get
        {
            return ViewState["ErrorMessage"].ToString();
        }

        set
        {
            ViewState["ErrorMessage"] = value;
        }
    }
    #endregion

    #region EmailSent
    protected string EmailSent
    {
        get
        {
            return ViewState["EmailSent"].ToString();
        }

        set
        {
            ViewState["EmailSent"] = value;
        }
    }
    #endregion

    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        SessionCheck();
        this.Table_MessageBox.Visible = false;

        if (!IsPostBack)
        {
            this.PageComponentSetup();
            this.SwitchLanguage();
        }
    }
    protected void Button_Send_Click(object sender, EventArgs e)
    {
        using (EmailFactory MailEngine = new EmailFactory(
            this.TextBox_ReceiverName.Text,
            this.TextBox_ReceiverEmail.Text,
            this.TextBox_Title.Text,
            this.TextBox_Content.Text))
        {
            if (MailEngine.SendNow())
            {
                // log down the history
                this.CurLogManager.LogMessage("[GonzalesAdminTestEmail] : Test Email (" + this.TextBox_ReceiverName.Text + ", " + this.TextBox_ReceiverEmail.Text + ", '" + this.TextBox_Title.Text + "', '" + this.TextBox_Content.Text + "') sent ", this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);


                this.ShowMessage(this.EmailSent);
            }
            else
            {
                this.ShowErrorMessage(this.ErrorMessage + MailEngine.ErrorMessage);
            }
        }
        
    }

    protected void ImageButton_Cancel_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("GonzalesAdminMain.aspx");
    }

    #region Customized Methods

    #region SessionCheck
    public void SessionCheck()
    {

        if (Session[GonzalesCommonNamingConvention.CurrentPrivateSession] != null)
        {
            this.CurrentPrivateSession = (PrivateLoginSession)Session[GonzalesCommonNamingConvention.CurrentPrivateSession];
            this.CurLogManager = new LogManager(this.CurrentPrivateSession);    // activate Log Manager
        }
        else
        {
            Response.Redirect(GonzalesErrorPageRedirect.SessionError);
        }

    }
    #endregion

    #region PageComponentSetup
    protected void PageComponentSetup()
    {

    }
    #endregion

    #region SwitchLanguage
    protected void SwitchLanguage()
    {
        try
        {
            using (MultiLingualFactory CurLanguageFactory = MultiLingualEngine.GetMultiLingualFactory(this, this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedLanguage.InternalID))
            {
                this.Label_Content.Text = CurLanguageFactory.DisplayValue("Content");
                this.Label_Information.Text = CurLanguageFactory.DisplayValue("Information");
                this.Label_PageTitle.Text = CurLanguageFactory.DisplayValue("PageTitle");
                this.Label_ReceiverEmail.Text = CurLanguageFactory.DisplayValue("ReceiverEmail");
                this.Label_ReceiverName.Text = CurLanguageFactory.DisplayValue("ReceiverName");
                this.Label_Title.Text = CurLanguageFactory.DisplayValue("Title");
                this.Button_Send.Text = CurLanguageFactory.DisplayValue("Send");
                this.ErrorMessage = CurLanguageFactory.DisplayValue("ErrorMessage");
                this.EmailSent = CurLanguageFactory.DisplayValue("EmailSent");
            }
        }
        catch (Exception ex)
        {
            this.CurLogManager.LogError("[GonzalesAdminClaimantsDetail.SwitchLanguage.EX] : " + ex.Message, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);
        }

    }
    #endregion

    #region ShowErrorMessage
    protected void ShowErrorMessage(string ErrorMessage)
    {
        this.Table_MessageBox.Visible = true;
        this.Table_MessageBox.Rows[0].Cells[0].Text = ErrorMessage;
        this.Table_MessageBox.Rows[0].Cells[0].CssClass = "ErrorBox";
    }
    #endregion

    #region ShowMessage
    protected void ShowMessage(string Message)
    {
        this.Table_MessageBox.Visible = true;
        this.Table_MessageBox.Rows[0].Cells[0].Text = Message;
        this.Table_MessageBox.Rows[0].Cells[0].CssClass = "MessageBox";
    }
    #endregion

    #endregion

}
